<?php session_start() ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Adopt a Pet from Kalamazoo Animal Rescue</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<? include("head.inc");  ?>
</head>
<body>
<!--initial body width and height set up  -->
<div id="bodywidth">
<? include("header.inc");  ?>
<? include("leftmenu.inc");  ?>
<!--wide2column enter here --><div id="wide2column">
<script language="JavaScript">

<!-- 
function open_new_window(url)
{ 
new_window = window.open(url,'window_name','toolbar=0,menubar=0,scrollbars=1,resizable=1,dependent=0,status=0,width=500,height=550,left=25,top=25')
}
</script>	
<?php
	
	// Variable is used to determine what type of pets to display
	$petType=$_GET['petType'];
	// Variable is used to determine sorting method
	$sortType=$_GET['sortType'];
	// Variable is used to determine sorting direction
	$sortDir=$_GET['sortDir'];
	// Variable stores starting number for the page
	$startting_num=$_GET['starting_num'];
	
include("db.php");
include("count.php");				// Connect to the database server
dbConnect('kar_web1');   	// Use function in db.php to connect

$numresults = @mysql_query("SELECT * FROM pets   WHERE pet_type='$petType' AND
						pet_status='v' AND 
						TO_DAYS(NOW()) - TO_DAYS(pet_DOB) <= 365");

if (!$numresults) {	
  echo("<p>Error performing query in Display Pets page: " . mysql_error() . "</p>");
  exit(); }

$num_to_display=15;  					//  Pets displayed per page
$num_columns=3;							// Columns to display
$num_pets=mysql_num_rows($numresults);	// Total animals that are available

if (empty($starting_num))
{	// if this is our first page, then start at 0
	$starting_num=0; }

$result = @mysql_query("SELECT * FROM pets WHERE pet_type='$petType' AND pet_status='v' AND 
 				   TO_DAYS(NOW()) - TO_DAYS(pet_DOB) <= 365
				   ORDER BY $sortType $sortDir
				   LIMIT $starting_num,$num_to_display");

